<template>
  <div class="animation">
    <RouterView v-slot="{ Component, route }">
      <transition :name="transitionName" :appear="true">
        <KeepAlive :include="keepLiveRoute" >
          <component v-if="inited" :is="Component" :key="route.name" />
        </KeepAlive>
      </transition>
    </RouterView>
  </div>
</template>

<script>
import {computed} from 'vue'
import {useStore} from 'vuex'
import { transitionName } from "./router/index";
export default {
  name: "App",
  data() {
    return {
      inited: false,
    };
  },
  setup() {
    const store = useStore();
    const keepLiveRoute= computed(()=> store.state.keepLiveRoute)
    

    return {
      transitionName,
      keepLiveRoute
    };
  },
  mounted() {
    this.inited = true;
  },
};
</script>

<style lang="less">
#app {
  overflow-x: hidden;
}
.animation {
  display: flex;
  width: 200%;
  flex: 1;
  overflow: hidden;

  & > div {
    width: 50%;
  }

  .slide-left-enter-active,
  .slide-left-leave-active,
  .slide-right-enter-active,
  .slide-right-leave-active {
    transition: transform 0.3s;
  }

  .slide-right-enter-from {
    transform: translateX(0);
  }
  .slide-right-enter-to {
    transform: translateX(-100%);
  }
  .slide-right-leave-from {
    transform: translateX(0);
  }
  .slide-right-leave-to {
    transform: translateX(-100%);
  }
  .slide-left-enter-from {
    transform: translateX(-200%);
  }
  .slide-left-enter-to {
    transform: translateX(-100%);
  }
  .slide-left-leave-from {
    transform: translateX(0);
  }
  .slide-left-leave-to {
    transform: translateX(100%);
  }
}
</style>
